﻿<%@ Page Language="C#" MasterPageFile="~/m_MasterPage.master" AutoEventWireup="true"
    CodeFile="m_ManageSuscripciones_Explore.aspx.cs" Inherits="m_ManageSuscripciones_Explore"
    Title="Explorar" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">    
    <div data-role="collapsible-set" data-content-theme="c" >
        <div data-role="collapsible" data-collapsed="false" >
           <h3>Listado</h3>
           <span class="membrete">Búsqueda</span>
            <asp:TextBox ID="txt_busqueda" runat="server"></asp:TextBox>
            <div data-role="collapsible" data-content-theme="c" style="margin-top:10px;">
                    <h3>Búsqueda Avanzada</h3>
                    <span class="membrete">Razón Social</span>
                    <input id="t_razonsoc" type="text" />
                    <span class="membrete">Rubro</span>
                    <input id="t_rubro" type="text" />
                    <span class="membrete">Descripción</span>
                    <input id="t_desc" type="text" />
                    <span class="membrete">Número de Publicación</span>
                    <input id="t_nropub" type="text" />
            </div>
            <asp:Button ID="btn_buscar" runat="server" Text="Buscar" OnClick="btn_buscar_Click" data-icon="search" data-iconpos="left" />
            <span class="membrete">Resultado</span>
            <asp:Label ID="lbl_nobusqueda" runat="server" Text="No se encontró ningún resultado para su búsqueda"></asp:Label>
            <asp:DataGrid ID="dg_Exploracion" runat="server" AutoGenerateColumns="false" CssClass="grilla">
                <Columns>
                    <asp:BoundColumn DataField="idempresa" Visible="false"></asp:BoundColumn>
                    <asp:BoundColumn DataField="idpublicacion" Visible="false"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Logo" HeaderText="Logo" HeaderStyle-Width="50" DataFormatString="<img alt='Logo' src='{0}' style='width:50px; height:50px;'></img>">
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="Descripcion" HeaderText="Descripción">
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="link" HeaderStyle-Width="50"></asp:BoundColumn>
                </Columns>
            </asp:DataGrid>
        </div>
        <div data-role="collapsible" >
            <h3 onclick="javascript:if(map!=null)return;setTimeout(function(){initialize();drop()},1000);">Mapa Localizador</h3>
            <div id="map_canvas" style="width: 100%; height: 300px;">
                <div class="t_cent">
                    <img src="static/loading.gif" alt="..." class="blk b_cent" /><span>Cargando mapa</span>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        jqm_prev_page = { url: '<%= Utils.SecureRedirect("m_ManageSuscripciones_Mias.aspx") %>', caption:'Mis suscripciones' };
        jqm_next_page = { url: '<%= Utils.SecureRedirect("m_AdminPanel.aspx") %>', caption:'Mis datos' };
       
		var latLongC = [-34.6106, -58.3853];	
		
		function getLocation(){
		    try {
			if (navigator.geolocation) {
				// Get current position
				navigator.geolocation.getCurrentPosition(
					function (position) {
						// Success!
						latLongC = [position.coords.latitude, position.coords.longitude];
					},
					null,
					{timeout:2000}
				);
			}
		    }
		    catch(err){}
		 }
		 getLocation();
		 
        /*
      var markers_info = [
        { title : "Prueba 1", info : "Prueba info 1", localization : new google.maps.LatLng(52.511467, 13.447179) },
        { title : "Prueba 2", info : "Prueba info 2", localization : new google.maps.LatLng(52.549061, 13.422975) },
        { title : "Prueba 3", info : "Prueba info 3", localization : new google.maps.LatLng(52.497622, 13.396110) },
        { title : "Prueba 4", info : "Prueba info 4", localization : new google.maps.LatLng(52.517683, 13.394393) }
      ];
        */
      var markers = [];
      var markers_info = [];
      
      <%= empresas %>
            
      var iterator = 0;
      var map = null;

      function initialize() {
        try {
		    var mapOptions = {
              zoom: 12,
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              center: new google.maps.LatLng(latLongC[0],latLongC[1])
            };
    		
            map = new google.maps.Map(document.getElementById('map_canvas'),
                    mapOptions);
                    
            // Test 2: Binding to document with on() handler recommended as of 1.7 with and without preventDefault
            $(document.getElementById('map_canvas')).bind('swipeleft',function(event, data){
                event.stopImmediatePropagation();
            });
            $(document.getElementById('map_canvas')).bind('swiperight',function(event, data){
                event.stopImmediatePropagation();
            });
        }
        catch(err){}

      }

      function drop() {
        for (var i = 0; i < markers_info.length; i++) {
          setTimeout(function() {
            addMarker();
          }, i * 300);
        }
      }

      var infowindow = null;

      function addMarker() {
        try {
            var marker = new google.maps.Marker({
                                  position: markers_info[iterator].localization,
                                  map: map,
                                  draggable: false,
                                  animation: google.maps.Animation.DROP,
                                  title: markers_info[iterator].title,
                                  info: markers_info[iterator].info                              
                                })
            markers.push(marker);
            iterator++;
            
            google.maps.event.addListener(marker, 'click', function() {
              if(infowindow != null)
                infowindow.close();
                
              infowindow = new google.maps.InfoWindow({
                    content: this.info,
                    maxWidth: 350
                });
              
              infowindow.open(map,this);
              
            });
        }
        catch(err) {}
      }
      
      $(document).bind( 'pagechange', function(){
        var busqueda = $('#<%= txt_busqueda.ClientID  %>');
            
        busqueda.change(function () { $("#t_razonsoc, #t_rubro, #t_desc, #t_nropub").val(""); });
        
        $("#t_razonsoc, #t_rubro, #t_desc, #t_nropub").change(function(){
           var texto = "";
           
           var r = $("#t_razonsoc").val();
           if(r != "")
           {
                if (texto != "")
                    texto += " ";    
                texto += "razon:" + r;
           }
            
           var ru = $("#t_rubro").val();
           if(ru != "")
           {
                if (texto != "")
                    texto += " ";    
                texto += "rubro:" + ru;
           }
            
           var d = $("#t_desc").val();
           if(d != "")
           {
                if (texto != "")
                    texto += " ";    
                texto += "desc:" + d;
           }
           
           var n = $("#t_nropub").val();
           if(n != "")
           {
                if (texto != "")
                    texto += " ";    
                texto += "nro:" + n;
           }
            
           if(texto != "")
                busqueda.val(texto);
        });
    });
    </script>

</asp:Content>
